<?php
/**************************************************************************
 *
 *   Copyright 2010 American Public Media Group
 *
 *   This file is part of AIR2.
 *
 *   AIR2 is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   AIR2 is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with AIR2.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************/

/*
|--------------------------------------------------------------------------
| AIR2 Inquiry View
|--------------------------------------------------------------------------
| Load inline data for the inquiry page
|   $base_url - base url of this inquiry
|   $inq      - json of this inquiry
*/

$ques1 = current(reset($ques['radix']));
$q1uuid = $ques1['ques_uuid'];

?>
<script type="text/javascript">
    AIR2.Inquiry.BASEURL   = '<?php echo $base_url; ?>';
    AIR2.Inquiry.ACTIVDATA = <?php echo isset($act)    ? json_encode($act)   : 'null'; ?>;
    AIR2.Inquiry.INQDATA   = <?php echo isset($inq)    ? json_encode($inq)   : 'null'; ?>;
    AIR2.Inquiry.STATSDATA = <?php echo isset($stats)  ? json_encode($stats) : 'null'; ?>;
    AIR2.Inquiry.QUESDATA  = <?php echo isset($ques)   ? json_encode($ques)  : 'null'; ?>;
    AIR2.Inquiry.TAGDATA   = <?php echo isset($tag)    ? json_encode($tag)   : 'null'; ?>;

    //AIR2.Inquiry.QSELECT = AIR2.Inquiry.Q1UUID;

    AIR2.Inquiry.sourceCityState = function(srcMailObj) {
        var cs = srcMailObj.smadd_city ? srcMailObj.smadd_city : '';
        if (srcMailObj.smadd_city && srcMailObj.smadd_state )
                cs = cs + ', ';
        cs = cs + ( srcMailObj.smadd_state ? srcMailObj.smadd_state : '');
        return cs;
    }

    AIR2.Inquiry.submDT = function(dtimStr) {
        if (!dtimStr) return '';
        //return dtimStr;
        return dtimStr.format("n/j/Y \\a\\t n:i a");
    }

    AIR2.Inquiry.firstVita = function(srcVitaArray) {
        if (!srcVitaArray) return "";
        var srcvita = '';
        var found = false;

        for ( var i in srcVitaArray ) {
            if ( srcVitaArray[i].sv_value && (! found) ){
                srcvita = Ext.util.Format.ellipsis(srcVitaArray[i].sv_value, 36, true);
                found = true;
            }
        }

        return srccred;
    }

    AIR2.Inquiry.filterResp = function(selObj) {
        var selValue;
        for (var i = 0; i < selObj.options.length; i++) {
            if (selObj.options[ i ].selected) {
               selValue = selObj.options[ i ].value;
            }
        }
        AIR2.Inquiry.QSELECT = selValue;
        AIR2.Inquiry.submPanel.store.filter('ques_uuid', selValue);
    }

    Ext.onReady(AIR2.Inquiry);
</script>
